package algorithm.sort.test;

import algorithm.sort.basic.Sort;
import algorithm.sort.child.*;
import utility.Asserts;
import utility.Tools;

import java.util.Arrays;

/**
 * 项目名称: god
 * 包 名 称: algorithm.sort.test
 * 类 名 称: Main
 * 类 描 述: TODO
 * 创建时间: 2020/6/22 9:51 下午
 * 创 建 人: Justice
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public class Main {
    public static void main(String[] args) {
        Integer[] random = Tools.random(10000, 0, 100000);
        testSorts(random, new BubbleSort3());
        testSorts(random, new SelectionSort());
        testSorts(random, new InsertSort3());
        testSorts(random, new MergeSort());
        testSorts(random, new QuickSort());
        testSorts(random, new ShellSort());
        testSorts(random, new HeapSort());
        testSorts(random, new CountSort2());
        testSorts(random, new RadixSort());
        testSorts(random, new BucketSort());
    }

    public static void testSorts(Integer[] array, Sort... sorts) {
        for (Sort sort : sorts) {
            Integer[] newArray = Tools.copy(array);
            sort.sort(newArray);
            Asserts.test(Tools.isAscOrder(newArray));
        }
        Arrays.sort(sorts);
        for (Sort sort : sorts) {
            System.out.println(sort);
        }
    }
}
